﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MetroFramework;
using DAQ.Common;
using DAQ.PROTOCOL;

namespace DAQ
{
    public partial class BTSR_PCLINK : MetroFramework.Controls.MetroUserControl
    {
        public PC_LINK pc_link { get; set; }
        public BTSR_PCLINK()
        {
            InitializeComponent();
            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    if (pc_link != null)
                    {
                        this.Invoke(new MethodInvoker(() =>
                        {
                            this.metroTile1.Text = string.Format($"CWF IDENTIFY {pc_link.COM_ID}");
                            this.tention_display.Text = pc_link.TENSION_DISPLAY_AVERAGE.ToString();
                            this.motor1temp.Text = pc_link.MOTOR_1_TEMPERATURE.ToString();
                            this.motor2temp.Text = pc_link.MOTOR_2_TEMPERATURE.ToString();
                            this.worktension.Text = pc_link.WORK_TENSION.ToString();
                            if (pc_link.ALARM_STATUS_A > 0 || pc_link.ALARM_STATUS_B > 0)
                            {
                                if (pc_link.VBUS_ALARM)
                                {

                                }
                                if (pc_link.MOTOR_2_ALARM)
                                {
                                    ALARM.Text = "MOTOR_2_ALARM";
                                }
                                if (pc_link.MOTOR_1_ALARM) { ALARM.Text = "MOTOR_1_ALARM"; }
                                if (pc_link.TARGET_ALARM) { ALARM.Text = "TARGET_ALARM"; }
                                if (pc_link.TEMPERATURE_ALARM) { ALARM.Text = "TEMPERATURE_ALARM"; }
                                if (pc_link.E3_ALARM) { ALARM.Text = "E3_ALARM"; }
                                if (pc_link.E2_ALARM) { ALARM.Text = "E2_ALARM"; }
                                if (pc_link.TENSION_ERROR) { ALARM.Text = "TENSION_ERROR"; }
                                if (pc_link.WARNING) { ALARM.Text = "WARNING"; }
                                if (pc_link.STEPPER_HIGH_ERROR) { ALARM.Text = "STEPPER_HIGH_ERROR"; }
                                if (pc_link.STEPPER_LOW_ERROR) { ALARM.Text = "STEPPER_LOW_ERROR"; }
                                if (pc_link.INPUT_CURRENT_ALARM) { ALARM.Text = "INPUT_CURRENT_ALARM"; }
                                if (pc_link.TENSION_ERROR_MEMORY) { ALARM.Text = "TENSION_ERROR_MEMORY"; }                           
                            }
                            else
                            {
                                ALARM.Text = "";
                            }
                        }));
                    }
                    System.Threading.Thread.Sleep(10);
                }
            });
        }


    }
}
